package com.atguigu.springboot.service.impl;

import com.atguigu.springboot.entities.Register;
import com.atguigu.springboot.entities.RegisterExample;
import com.atguigu.springboot.mapper.RegisterMapper;
import com.atguigu.springboot.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("registerService")
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    RegisterMapper registerMapper;
    @Override
    public boolean register(int uid, int aid) {
        Register re=new Register();
        re.setUid(uid);
        re.setAid(aid);

        //判断重复打卡
        RegisterExample registerExample=new RegisterExample();
        RegisterExample.Criteria criteria=registerExample.createCriteria();
        criteria.andUidEqualTo(uid);
        criteria.andAidEqualTo(aid);
       List<Register> list= registerMapper.selectByExample(registerExample);
       if(list==null||list.size()==0){
           return  registerMapper.insert(re)>0;
       }else return false;


    }
}
